const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
const webpack = require("webpack")
const CompressionPlugin = require("compression-webpack-plugin")


module.exports = {
  publicPath: "/",
  outputDir: "dist",
  productionSourceMap: false,
  devServer: {
    /* headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "*",
      "Access-Control-Allow-Methods": "*",
    }, */
    port: "2345",
  },
  /* configureWebpack: () => {
    return {
      externals: {
        vue: "Vue",
        "vue-router": "VueRouter",
        vuex: "Vuex",
        "element-ui": "ELEMENT",
      },
    }
  }, */
  chainWebpack: config => {
    config.optimization.splitChunks({
      chunks: "all",
      maxInitialRequests: Infinity,
      minSize: 600000,
      automaticNameDelimiter: "-",
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name(module) {
            const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
            return `chunk.${packageName.replace("@", "")}`
          },
          priority: 10,
        },
      },
    })
  },
  configureWebpack: config => {
    // console.log("--------configureWebpack----------", config)
    config.resolve.extensions = [".js", ".vue", ".json"]
    if (process.env.NODE_ENV == "development") {
      config.plugins.push(new BundleAnalyzerPlugin({ analyzerPort: 2355 }))
    }
    // config.plugins.push(new webpack.CachePlugin())
    // config.plugins.push(new CompressionPlugin())
    // return config
  },
}
